<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<include file="Public/title" />
<script src="__PUBLIC__/home/js/mobiscroll.2.13.2.js"></script>
<link href="__PUBLIC__/home/css/mobiscroll.2.13.2.css" rel="stylesheet" />
</head>

<body>
<div class="mainWrap">
    <!--标题-->
    <div class="mainWrapHeader">
    	<h1 class="mainWrapTit">{$seotitle}</h1>
    </div>
    <!--标题-->
    <form action="{:U('save',array('action'=>'add'))}" method="post" class="dataForm" id="dataForm">
    <div class="mainWrapBd">
    	<div class="tab-con" id="tab-works">
            <table cellpadding="0" border="0" cellspacing="0" class="stdedit">
                <tr>
                    <th>任务名称</th>
                    <td><input type="text" name="name" id="name" class="sys_text" /></td>
                </tr>
                <tr>
                    <th>所属项目</th>
                    <td>
                    <input type="text" type="checkbox" name='project_name' class="sys_text" id='xm' value=''>
                    <li id='show_project' style="list-style: none;"><label><img src="__PUBLIC__/home/images/ico+.png">展开项目</label></li>
                    <!--弹出折叠项目-->
                    <div class="popbox" style="display:none;">
                        <div class="popbd">
                            <div class="hd"><h3>项目</h3><div class="mclose">确定</div></div>
                            <ul class="diytree">
                            <span class="control">收起/展开</span>
                                <foreach name="info" item="vo"> 
                                <if condition="$vo['flag'] eq 1">      
                                <li><label><img src="__PUBLIC__/home/images/ico-.png">{$vo['value']}</label>
                                    <ul>
                                        <foreach name="vo.childs" item="vo1">
                                        <if condition="$vo1['flag'] eq 1">  
                                        <li><label><img src="__PUBLIC__/home/images/ico-.png">{$vo1['value']}</label>
                                            <ul>
                                                <foreach name="vo1.childs" item="vo2">  
                                                <li><label><input name="" type="checkbox" value="{$vo2['id']}" title="{$vo2['title']}">{$vo2['value']}</label></li>
                                                </foreach>
                                            </ul>
                                        </li>
                                        <else />
                                        <li><label><input name="" type="checkbox" value="{$vo1['id']}" title="{$vo1['title']}">{$vo1['value']}</label>
                                        </if>
                                        </foreach>    
                                        </li>
                                    </ul>
                                </li>
                                <else />
                                <li><label><input name="" type="checkbox" value="{$vo['id']}" title="{$vo['title']}">{$vo['value']}</label></li>
                                </if>
                                </foreach>
                             </ul>
                        </div>
                    </div>
                    </td>
                </tr>
                <tr>
                    <th>任务截止时间</th>
                    <td><input type="text" name="end_time" id="end_time" class="sys_text"/></td>
                </tr>
                <tr>
                    <th>跟进人员</th>
                    <td>
                        <?php
                            $user = M('user a')->order("a.id desc")->select();
                        ?>
                        <div class="setWrap ruleWrap ruleWrapCur">
                            <div class="setWrapTit"><label><input type="checkbox">全选/反选</label></div>
                            <div class="setWrapBody">
                                <ul class="clearfix ruleList">
                                    <volist name="user" id="foo">
                                    <li><label><input type="checkbox" name="follow_user_id[]" value="{$foo['id']}"> {$foo['nickname']}</label></li>
                                    </volist>
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>抄送人员</th>
                    <td>
                        <div class="setWrap ruleWrap ruleWrapCur">
                            <div class="setWrapTit"><label><input type="checkbox">全选/反选</label></div>
                            <div class="setWrapBody">
                                <ul class="clearfix ruleList">
                                    <volist name="user" id="foo">
                                    <li><label><input type="checkbox" name="cc_user_id[]" value="{$foo['id']}"> {$foo['nickname']}</label></li>
                                    </volist>
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>备注</th>
                    <td><textarea name="remark" id="remark" class="sys_text" cols="100" rows="4"></textarea></td>
                </tr>
            </table>
        </div>        
        <div class="stdeditSubmit"><input type="submit" class="submit" value="提 交" /> <input type="button" value="返回上一页" class="reset" onclick="history.go(-1);" /></div>
        <input type="hidden" type="checkbox" name='project_id' id='xmid' value=''>
    </div>
    </form>
    
</div>
</body>
</html>

<script type="text/javascript">
$(function(){   

    var myDate = new Date()
    var y = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
    var m = myDate.getMonth(); //获取当前月份(0-11,0代表1月)
    var d = myDate.getDate(); //获取当前日(1-31)
    var w = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
    var h = myDate.getHours(); //获取当前小时数(0-23)
    var f = myDate.getMinutes(); //获取当前分钟数(0-59)
    var tmpArr = new Array('周日','周一','周二','周三','周四','周五','周六');
    var s = (m+1) + '月' + d + '日' + tmpArr[w] + ' ' + h + ':' + f;
    var s = y + '-' + (m+1) + '-' + d  + ' ' + h + ':' + f;
    $('#end_time').val(s);


    /*日期*/
    var curr = new Date().getFullYear();
    var opt={};
    opt.date = {preset : 'date'};
    opt.datetime = {preset : 'datetime'};
    opt.time = {preset : 'time'};
    opt.default = {
        theme: 'android-holo light', //皮肤样式
        display: 'modal', //显示方式 
        mode: 'scroller', //日期选择模式
        // dateFormat: 'yy年mm月dd日DD',
        dateFormat: 'yy-mm-dd',
        lang: 'zh',
        showNow: true,
        nowText: "今天",
        stepMinute: 5,
        yearText: '年', monthText: '月', dayText: '日', //面板中年月日文字
        startYear: curr - 0, //开始年份
        endYear: curr + 1 //结束年份
    };
    
    $('#end_time').scroller('destroy').scroller($.extend(opt['datetime'], opt['default']));

    //权限功能
    $(".ruleWrap").each(function(){
        var i=$(this);
        var t=i.find(".setWrapTit");
        var t_label=t.find("label");
        var label_input=t_label.find("input[type='checkbox']");
        var b=i.find(".setWrapBody");
        //展开关闭
        t.click(function(e){
            if(!$(e.target).closest("label").is(t_label)){
                if(b.is(":hidden") && !b.is(":animated")){
                    i.addClass("ruleWrapCur");
                    b.slideDown(200);
                }else{
                    i.removeClass("ruleWrapCur");
                    b.slideUp(200);
                }
            }
        })
        //全选/全部选
        label_input.click(function(){
            b.find("input[type='checkbox']").attr("checked",!!label_input.attr("checked"))
        })
        
        //获取状态
        var checkFun=function(){
            checked_num=b.find("input:checked").size();
            checked_count=b.find("input[type='checkbox']").size()
            label_input.get(0).indeterminate=false;
            if(checked_num==checked_count && checked_count!=0){
                label_input.attr("checked",true);
            }else if(checked_num==0){
                label_input.attr("checked",false);
            }else{
                label_input.get(0).indeterminate=true;
            }
        }
        
        //部分
        b.find("input[type='checkbox']").click(function(){
            checkFun();
        })
        
        //初始化
        checkFun();
    })

    //项目选择折叠收起
    $('.diytree li label').click(function() {
        var isShow = $(this).parent().find("ul").is(":visible");
        if(isShow==false){
            $(this).find("img").attr("src","__PUBLIC__/home/images/ico-.png");
             $(this).parent().find("ul").slideDown();
        }
        else{
            $(this).find("img").attr("src","__PUBLIC__/home/images/ico+.png");
             $(this).parent().find("ul").slideUp();
        }
    });
    var isopen=1;
    $('.diytree .control').click(function() {
        if(isopen==1){
            $('.diytree img').attr("src","__PUBLIC__/home/images/ico+.png");
            $('.diytree li ul').slideUp();
            isopen=0;
        }
        else{
            $('.diytree img').attr("src","__PUBLIC__/home/images/ico-.png");
            $('.diytree li ul').slideDown();
            isopen=1;
        }
    });
    /*项目*/
    $('#show_project').click(function(){
        $('.popbox').css('display','block');  
    })
    $('.popbox .mclose').click(function() { 
        $('.popbox').css('display','none');
        checkitemval();
    });
    function checkitemval(){
        var ids = '';
        var names = '';
         $('.diytree input:checkbox:checked').each(function (index, item) {
            ids += $(this).val() + '|';
            names += $(this).attr("title") + '|';
            $("#xm").val(names);
        });
        ids = ids.replace(/\|$/gi,'');//去出末尾 |
        names = names.replace(/\|$/gi,'');//去出末尾 |
        //console.log(ids);
        //console.log(names);
        $('#xm').val(names);
        $('#xmid').val(ids);
    }
})
</script>
